﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace Ordinaire.Tool
{
    /// <summary>
    /// Formatter class provides formatting functions of any type.
    /// </summary>
    public class Formatter
    {
        /// <summary>
        /// Trim input text.
        /// </summary>
        /// <param name="input">input text</param>
        /// <returns>trimmed text or empty string</returns>
        public static string Trim(string input)
        {
            return Trim(input, true);
        }

        /// <summary>
        /// Trim input text.
        /// </summary>
        /// <param name="input">input text</param>
        /// <param name="nullAsEmpty">return empty string for null input</param>
        /// <returns>trimmed text or null or empty</returns>
        public static string Trim(string input, bool nullAsEmpty)
        {
            if (String.IsNullOrEmpty(input))
            {
                return (nullAsEmpty) ? String.Empty : null;
            }

            return input.Trim();
        }
    }
}
